<!DOCTYPE html><html><head>
<title>transfer::connect - Data transfer facilities</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'connect.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2006-2009 Andreas Kupries &amp;lt;andreas_kupries@users.sourceforge.net&amp;gt;
   -->
<!-- transfer::connect.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">transfer::connect(n) 0.2 tcllib &quot;Data transfer facilities&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>transfer::connect - Connection setup</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">API</a>
<ul>
<li class="doctools_subsection"><a href="#subsection1">Package commands</a></li>
<li class="doctools_subsection"><a href="#subsection2">Object command</a></li>
<li class="doctools_subsection"><a href="#subsection3">Object methods</a></li>
<li class="doctools_subsection"><a href="#subsection4">Options</a></li>
</ul>
</li>
<li class="doctools_section"><a href="#section3">Secure connections</a></li>
<li class="doctools_section"><a href="#section4">TLS Security Considerations</a></li>
<li class="doctools_section"><a href="#section5">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.4</b></li>
<li>package require <b class="pkgname">snit <span class="opt">?1.0?</span></b></li>
<li>package require <b class="pkgname">transfer::connect <span class="opt">?0.2?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">transfer::connect</b> <i class="arg">objectName</i> <span class="opt">?<i class="arg">options</i>...?</span></a></li>
<li><a href="#2"><i class="arg">objectName</i> <b class="method">method</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></li>
<li><a href="#3"><i class="arg">objectName</i> <b class="method">destroy</b></a></li>
<li><a href="#4"><i class="arg">objectName</i> <b class="method">connect</b> <i class="arg">command</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This package provides objects holding enough information to enable
them to either actively connect to a counterpart, or to passively wait
for a connection from said counterpart.
I.e. any object created by this packages is always in one of two
complementary modes, called <i class="term"><a href="../../../../index.html#active">active</a></i> (the object initiates the
connection) and <i class="term"><a href="../../../../index.html#passive">passive</a></i> (the object receives the connection).</p>
<p>Of the two objects in a connecting pair one has to be configured for
<i class="term"><a href="../../../../index.html#active">active</a></i> mode, and the other then has to be configured for
<i class="term"><a href="../../../../index.html#passive">passive</a></i> mode. This establishes which of the two partners
connects to whom (the <i class="term"><a href="../../../../index.html#active">active</a></i> to the other), or, who is waiting
on whom (the <i class="term"><a href="../../../../index.html#passive">passive</a></i> on the other).
Note that this is completely independent of the direction of any data
transmission using the connection after it has been established.
An active object can, after establishing the connection, either
transmit or receive data. Equivalently the passive object can do the
same after the waiting for its partner has ended.</p>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2>
<div id="subsection1" class="doctools_subsection"><h3><a name="subsection1">Package commands</a></h3>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">transfer::connect</b> <i class="arg">objectName</i> <span class="opt">?<i class="arg">options</i>...?</span></a></dt>
<dd><p>This command creates a new connection object with an associated Tcl
command whose name is <i class="arg">objectName</i>.
This <i class="term"><a href="../../../../index.html#object">object</a></i> command is explained in full detail in the sections
<span class="sectref"><a href="#subsection2">Object command</a></span> and <span class="sectref"><a href="#subsection3">Object methods</a></span>. The set of
supported <i class="arg">options</i> is explained in section <span class="sectref"><a href="#subsection4">Options</a></span>.</p>
<p>The object command will be created under the current namespace if the
<i class="arg">objectName</i> is not fully qualified, and in the specified
namespace otherwise.
The fully qualified name of the object command is returned as the
result of the command.</p></dd>
</dl>
</div>
<div id="subsection2" class="doctools_subsection"><h3><a name="subsection2">Object command</a></h3>
<p>All objects created by the <b class="cmd">::transfer::connect</b> command have the
following general form:</p>
<dl class="doctools_definitions">
<dt><a name="2"><i class="arg">objectName</i> <b class="method">method</b> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></dt>
<dd><p>The method <b class="method">method</b> and its <i class="arg">arg</i>'uments determine the
exact behavior of the command.
See section <span class="sectref"><a href="#subsection3">Object methods</a></span> for the detailed
specifications.</p></dd>
</dl>
</div>
<div id="subsection3" class="doctools_subsection"><h3><a name="subsection3">Object methods</a></h3>
<dl class="doctools_definitions">
<dt><a name="3"><i class="arg">objectName</i> <b class="method">destroy</b></a></dt>
<dd><p>This method destroys the object.
This is safe to do for an <i class="term"><a href="../../../../index.html#active">active</a></i> object when a connection has
been started, as the completion callback is synchronous.
For a <i class="term"><a href="../../../../index.html#passive">passive</a></i> object currently waiting for its partner to
establish the connection however this is not safe and will cause
errors later on, when the connection setup completes and tries to
access the now missing data structures of the destroyed object.</p></dd>
<dt><a name="4"><i class="arg">objectName</i> <b class="method">connect</b> <i class="arg">command</i></a></dt>
<dd><p>This method starts the connection setup per the configuration of the
object. When the connection is established the callback <i class="arg">command</i>
will be invoked with one additional argument, the channel handle of
the socket over which data can be transfered.</p>
<p>The detailed behaviour of the method depends on the configured
mode.</p>
<dl class="doctools_definitions">
<dt><i class="term"><a href="../../../../index.html#active">active</a></i></dt>
<dd><p>The connection setup is done synchronously. The object waits until the
connection is established. The method returns the empty string as its
result.</p></dd>
<dt><i class="term"><a href="../../../../index.html#passive">passive</a></i></dt>
<dd><p>The connection setup is done asynchronously. The method returns
immediately after a listening socket has been set up. The connection
will be established in the background.
The method returns the port number of the listening socket, for use by
the caller. One important use is the transfer of this information to
the counterpart so that it knows where it has to connect to.</p>
<p>This is necessary as the object might have been configured for port
<b class="const">0</b>, allowing the operating system to choose the actual port it
will listen on.</p>
<p>The listening port is closed immediately when the connection was
established by the partner, to keep the time interval small within
which a third party can connect to the port too.
Even so it is recommended to use additional measures in the protocol
outside of the connect and transfer object to ensure that a connection
is not used with an unidentified/unauthorized partner
One possibility for this is the use of SSL/TLS.
See the option <b class="option">-socketcmd</b> and section
<span class="sectref"><a href="#section3">Secure connections</a></span> for information on how to do this.</p></dd>
</dl></dd>
</dl>
</div>
<div id="subsection4" class="doctools_subsection"><h3><a name="subsection4">Options</a></h3>
<p>Connection objects support the set of options listed below.</p>
<dl class="doctools_options">
<dt><b class="option">-mode</b> <i class="arg">mode</i></dt>
<dd><p>This option specifies the mode the object is in. It is optional and
defaults to <b class="const">active</b> mode. The two possible modes are:</p>
<dl class="doctools_definitions">
<dt><b class="const">active</b></dt>
<dd><p>In this mode the two options <b class="option">-host</b> and <b class="option">-port</b> are
relevant and specify the host and TCP port the object has to connect
to. The host is given by either name or IP address.</p></dd>
<dt><b class="const">passive</b></dt>
<dd><p>In this mode the option <b class="option">-host</b> has no relevance and is ignored
should it be configured.
The only option the object needs is <b class="option">-port</b>, and it specifies
the TCP port on which the listening socket is opened to await the
connection from the partner.</p></dd>
</dl></dd>
<dt><b class="option">-host</b> <i class="arg">hostname-or-ipaddr</i></dt>
<dd><p>This option specifies the host to connect to in <i class="term"><a href="../../../../index.html#active">active</a></i> mode,
either by name or ip-address. An object configured for <i class="term"><a href="../../../../index.html#passive">passive</a></i>
mode ignores this option.</p></dd>
<dt><b class="option">-port</b> <i class="arg">int</i></dt>
<dd><p>For <i class="term"><a href="../../../../index.html#active">active</a></i> mode this option specifies the port the object is
expected to connect to. For <i class="term"><a href="../../../../index.html#passive">passive</a></i> mode however it is the port
where the object creates the listening socket waiting for a
connection. It defaults to <b class="const">0</b>, which allows the OS to choose
the actual port to listen on.</p></dd>
<dt><b class="option">-socketcmd</b> <i class="arg">command</i></dt>
<dd><p>This option allows the user to specify which command to use to open a
socket. The default is to use the builtin <b class="cmd">::socket</b>. Any
compatible with that command is allowed.</p>
<p>The envisioned main use is the specfication of <b class="cmd">tls::socket</b>. I.e.
this option allows the creation of secure transfer channels, without
making this package explicitly dependent on the <b class="package"><a href="../../../../index.html#tls">tls</a></b> package.</p>
<p>See also section <span class="sectref"><a href="#section3">Secure connections</a></span>.</p></dd>
<dt><b class="option">-encoding</b> encodingname</dt>
<dd></dd>
<dt><b class="option">-eofchar</b> eofspec</dt>
<dd></dd>
<dt><b class="option">-translation</b> transspec</dt>
<dd><p>These options are the same as are recognized by the builtin command
<b class="cmd">fconfigure</b>. They provide the configuration to be set for the
channel between the two partners after it has been established, but
before the callback is invoked (See method <b class="method">connect</b>).</p></dd>
</dl>
</div>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">Secure connections</a></h2>
<p>One way to secure connections made by objects of this package is to
require the package <b class="package"><a href="../../../../index.html#tls">tls</a></b> and then configure the option
<b class="option">-socketcmd</b> to force the use of command <b class="cmd">tls::socket</b> to
open the socket.</p>
<pre class="doctools_example">
    # Load and initialize tls
    package require tls
    tls::init -cafile /path/to/ca/cert -keyfile ...
    # Create a connector with secure socket setup,
    transfer::connect C -socketcmd tls::socket ...
    ...
</pre>
</div>
<div id="section4" class="doctools_section"><h2><a name="section4">TLS Security Considerations</a></h2>
<p>This package uses the <b class="package"><a href="../../../../index.html#tls">TLS</a></b> package to handle the
security for <b class="const">https</b> urls and other socket connections.</p>
<p>Policy decisions like the set of protocols to support and what
ciphers to use are not the responsibility of <b class="package"><a href="../../../../index.html#tls">TLS</a></b>, nor of
this package itself however.
Such decisions are the responsibility of whichever application is
using the package, and are likely influenced by the set of servers
the application will talk to as well.</p>
<p>For example, in light of the recent
<a href="http://googleonlinesecurity.blogspot.co.uk/2014/10/this-poodle-bites-exploiting-ssl-30.html">POODLE attack</a> discovered by Google many servers will disable support
for the SSLv3 protocol.
To handle this change the applications using <b class="package"><a href="../../../../index.html#tls">TLS</a></b> must be
patched, and not this package, nor <b class="package"><a href="../../../../index.html#tls">TLS</a></b> itself.
Such a patch may be as simple as generally activating <b class="const">tls1</b>
support, as shown in the example below.</p>
<pre class="doctools_example">
    package require tls
    tls::init -tls1 1 ;# forcibly activate support for the TLS1 protocol
    ... your own application code ...
</pre>
</div>
<div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>transfer</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#active">active</a>, <a href="../../../../index.html#channel">channel</a>, <a href="../../../../index.html#connection">connection</a>, <a href="../../../../index.html#passive">passive</a>, <a href="../../../../index.html#secure">secure</a>, <a href="../../../../index.html#ssl">ssl</a>, <a href="../../../../index.html#tls">tls</a>, <a href="../../../../index.html#transfer">transfer</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Transfer module</p>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2006-2009 Andreas Kupries &lt;andreas_kupries@users.sourceforge.net&gt;</p>
</div>
</div></body></html>
